package com.sky.config;

import com.sky.server.WebSocketServer;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;


/**
* 服务器启动或者停止时执行
 * @author Administrator
 */
@Component
public class ApplicationListens implements CommandLineRunner, DisposableBean {

    @Resource
    private WebSocketServer webSocketServer;

    /** 项目停止时清除netty服务器相关redis缓存 **/
    @Override
    public void destroy() throws Exception {
        webSocketServer.destroy();
    }

    /** 项目启动时启动netty服务器 **/
    @Override
    public void run(String... args) throws Exception {
        webSocketServer.start();
    }
}
